package com.powerhua.privilege;

import com.powerhua.core.bean.BeansRegisterLocator;
import com.powerhua.core.utils.PathUtils;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import com.powerhua.privilege.dao.GroupDao;
import com.powerhua.privilege.dao.OperationDao;
import com.powerhua.privilege.dao.OrgDao;
import com.powerhua.privilege.dao.PrivilegeDao;
import com.powerhua.privilege.dao.PositionDao;
import com.powerhua.privilege.dao.ResourceDao;
import com.powerhua.privilege.dao.RoleDao;
import com.powerhua.privilege.dao.UserDao;
import com.powerhua.privilege.logic.GroupManager;
import com.powerhua.privilege.logic.OperationManager;
import com.powerhua.privilege.logic.PrivilegeManager;
import com.powerhua.privilege.logic.ResourceManager;
import com.powerhua.privilege.logic.RoleManager;
import com.powerhua.privilege.logic.UserManager;

public class PrivilegeUtils {

    public static final String SESSION_CURRENT_USER = "currentUser";

    /*
     * permission DAO
     */
    public static OperationDao getOpDao() {
        return (OperationDao) BeansRegisterLocator.getBean("");
    }

    public static ResourceDao getResDao() {
        return (ResourceDao) BeansRegisterLocator.getBean("");
    }

    public static PrivilegeDao getPmDao() {
        return (PrivilegeDao) BeansRegisterLocator.getBean("");
    }

    public static GroupDao getGroupDao() {
        return (GroupDao) BeansRegisterLocator.getBean("");
    }

    public static UserDao getUserDao() {
        return (UserDao) BeansRegisterLocator.getBean("");
    }

    public static RoleDao getRoleDao() {
        return (RoleDao) BeansRegisterLocator.getBean("");
    }

    public static PositionDao getPositionDao() {
        return (PositionDao) BeansRegisterLocator.getBean("");
    }

    public static OrgDao getOrgDao() {
        return (OrgDao) BeansRegisterLocator.getBean("");
    }

    /*
     * permission manager
     */
    public static UserManager getUserManager() {
        return (UserManager) BeansRegisterLocator.getBean("userManager");
    }

    public static GroupManager getGroupManager() {
        return (GroupManager) BeansRegisterLocator.getBean("");
    }

    public static RoleManager getRoleManager() {
        return (RoleManager) BeansRegisterLocator.getBean("");
    }

    public static PrivilegeManager getPermissionManager() {
        return (PrivilegeManager) BeansRegisterLocator.getBean("");
    }

    public static OperationManager getOperationManager() {
        return (OperationManager) BeansRegisterLocator.getBean("");
    }

    public static ResourceManager getResourceManager() {
        return (ResourceManager) BeansRegisterLocator.getBean("");
    }

    /*
     * permission param properties
     */
    public static String getPermissionParamProperty(String key) {
        Properties prop = new Properties();
        InputStream in = null;
        String result = "";
        try {
            in = new BufferedInputStream(new FileInputStream(PathUtils.getClassBasePath() + "param-permission.properties"));
            prop.load(in);
            result = prop.getProperty(key);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return result;
    }
}